//
//  AddShopTableViewCell5.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/6/14.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "AddShopTableViewCell5.h"

@interface AddShopTableViewCell5 ()
{
    
}
@property (nonatomic,strong) MBProgressHUD *hub;
@end

@implementation AddShopTableViewCell5

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self getNoti];
}

//选择图片
- (IBAction)chooseImageButtonClick:(UIButton *)sender {
//    kAlert(@"点击选择图片");
//    [self showSheet];
    [[TakePicDelegate defaultManager] jumpAlarmInViewController:[self viewController] notiName:@"shopImage" type:@"0"];
}

- (void)getNoti{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shopImage:) name:@"shopImage" object:nil];
}

- (void)shopImage:(NSNotification *)noti{
    [_buttonChooseImage setBackgroundImage:[UIImage imageWithData:noti.object] forState:UIControlStateNormal];
    [self upLoadImage];
}

- (void)upLoadImage{
    [self.hub hideAnimated:YES];
    
    self.hub = [MBProgressHUD showHUDAddedTo:self animated:YES];
    
    // Set the label text.
    self.hub.label.text = NSLocalizedString(@"加载中...", @"HUD loading title");
    [[AFClient shareInstance] uploadImageByImage:_buttonChooseImage.currentBackgroundImage progressBlock:nil success:^(id responseBody) {
        [self.hub hideAnimated:YES];
        if ([responseBody[@"code"] integerValue] == 200) {
//            kAlert(@"图片上传成功");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"imgUrl" object:responseBody[@"data"]];
        }else{
            kAlert(responseBody[@"message"]);
        }
    } failure:^(NSError *error) {
        [self.hub hideAnimated:YES];
    }];
}

- (UIViewController *)viewController {
    UIResponder *next = self.nextResponder;
    do {
        //判断响应者是否为视图控制器
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = next.nextResponder;
    } while (next != nil);
    
    return nil;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
